<?php

namespace app\admin\model;

use think\Model;

class Goods extends Model {

    // 表名
    protected $name = 'goods';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'status_text'
    ];

    protected static function init() {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function getStatusList() {
        return \app\common\model\Dict::getMagicData('goods_status');
    }

    public function getStatusTextAttr($value, $data) {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getIs_selectList() {
        return \app\common\model\Dict::getMagicData('is');
    }

    public function getIs_selectTextAttr($value, $data) {
        $value = $value ? $value : $data['is_select'];
        $list = $this->getIs_selectList();
        return isset($list[$value]) ? $list[$value] : '';
    }

}
